{include file='admin/header.html'}

<!-- 顶部 -->
<!-- 移动端样式 -->
<style>
  body{background-color:#f2f2f2}
  .layui-layout-admin .layui-logo{color:#fff;background-color:rgba(0,0,0,.3)}
  .layui-layout-admin .layui-body{overflow-y:hidden}
  .layui-layout-admin .layui-side-shrink{left:-300px}
  .layui-layout-admin .layui-logo-shrink{left:-300px}
  .layui-layout-admin .layui-body-shrink{left:0}
  .layui-layout-admin .layui-layout-left-shrink{left:0}
  .layui-layout-admin .layui-footer-shrink{left:0}

  /* 移动端 */
  @media screen and (max-width:768px){
    .layui-layout-admin .layui-body,.layui-layout-admin .layui-footer,.layui-layout-admin .layui-layout-left{left:0}
    .layui-layout-admin .layui-side{left:-300px;z-index:1000}
    .layui-layout-admin .layui-header{z-index:999}
    .layui-layout-admin .layui-logo{z-index:1000}
    .site-mobile .layui-side{left:0}
    /* 遮罩层 */
    .site-mobile .site-mobile-shade{position:fixed;top:0;bottom:0;left:0;right:0;background-color:rgba(0,0,0,.3);z-index:999}
  }
</style>
<!-- 移动端样式end -->
<div class="site-mobile-shade" lay-header-event="menuShrink"></div>

<div class="layui-layout layui-layout-admin">
  <!-- header start -->
  <div class="layui-header">
    <!-- logo -->
    <div class="layui-logo layui-hide-xs" style="background:#23262E;cursor:pointer;" lay-header-event="backend"><i class="layui-icon layui-icon-console"></i> {$tran.backend}</div>
    <!-- 头部左侧区域 -->
    <ul class="layui-nav layui-layout-left">
      <!-- 移动端显示 -->
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
        <i class="layui-icon layui-icon-spread-left"></i>
      </li>
      <li class="layui-nav-item layui-show-md-inline-block layui-hide-xs" lay-header-event="menuLeftShrink">
        <i class="layui-icon layui-shrink layui-icon-shrink-right"></i>
      </li>
      <!-- 语言 -->
      {if $langs}
      <li class="layui-nav-item">
        <a href="javascript:;" title="{$tran.language}">
          <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="18" viewBox="0 0 24 28" style="vertical-align:middle;">
            <path d="M10.219 16.844c-0.031 0.109-0.797-0.25-1-0.328-0.203-0.094-1.125-0.609-1.359-0.766s-1.125-0.891-1.234-0.938v0c-0.562 0.859-1.281 1.875-2.094 2.828-0.281 0.328-1.125 1.391-1.641 1.719-0.078 0.047-0.531 0.094-0.594 0.063 0.25-0.187 0.969-1.078 1.281-1.437 0.391-0.453 2.25-3.047 2.562-3.641 0.328-0.594 1.312-2.562 1.359-2.75-0.156-0.016-1.391 0.406-1.719 0.516-0.313 0.094-1.172 0.297-1.234 0.344-0.063 0.063-0.016 0.25-0.047 0.313s-0.313 0.203-0.484 0.234c-0.156 0.047-0.516 0.063-0.734 0-0.203-0.047-0.391-0.25-0.438-0.328 0 0-0.063-0.094-0.078-0.359 0.187-0.063 0.5-0.078 0.844-0.172s1.188-0.344 1.641-0.5 1.328-0.484 1.594-0.547c0.281-0.047 0.984-0.516 1.359-0.641s0.641-0.281 0.656-0.203 0 0.422-0.016 0.516c-0.016 0.078-0.766 1.547-0.875 1.781-0.063 0.125-0.5 0.953-1.203 2.047 0.25 0.109 0.781 0.328 1 0.438 0.266 0.125 2.125 0.906 2.219 0.938s0.266 0.75 0.234 0.875zM7.016 9.25c0.047 0.266-0.031 0.375-0.063 0.438-0.156 0.297-0.547 0.5-0.781 0.594s-0.625 0.187-0.938 0.187c-0.141-0.016-0.422-0.063-0.766-0.406-0.187-0.203-0.328-0.75-0.266-0.688s0.516 0.125 0.719 0.078 0.688-0.187 0.906-0.25c0.234-0.078 0.703-0.203 0.859-0.219 0.156 0 0.281 0.063 0.328 0.266zM17.922 11.266l0.984 3.547-2.172-0.656zM0.609 23.766l10.844-3.625v-16.125l-10.844 3.641v16.109zM20 18.813l1.594 0.484-2.828-10.266-1.563-0.484-3.375 8.375 1.594 0.484 0.703-1.719 3.297 1.016zM12.141 3.781l8.953 2.875v-5.938zM17 24.453l2.469 0.203-0.844 2.5-0.625-1.031c-1.266 0.812-2.828 1.437-4.312 1.687-0.453 0.094-0.969 0.187-1.422 0.187h-1.313c-1.656 0-4.672-0.984-5.984-1.937-0.094-0.078-0.125-0.141-0.125-0.25 0-0.172 0.125-0.297 0.281-0.297 0.141 0 0.875 0.453 1.078 0.547 1.406 0.703 3.375 1.344 4.953 1.344 1.953 0 3.281-0.25 5.063-1.016 0.516-0.234 0.969-0.531 1.453-0.797zM24 7.594v16.859c-12.078-3.844-12.094-3.844-12.094-3.844-0.25 0.109-11.453 3.891-11.609 3.891-0.125 0-0.234-0.078-0.281-0.203 0-0.016-0.016-0.031-0.016-0.047v-16.844c0.016-0.047 0.031-0.125 0.063-0.156 0.094-0.109 0.219-0.141 0.313-0.172 0.047-0.016 1-0.328 2.328-0.781v-6l8.719 3.094c0.109-0.031 9.828-3.391 9.969-3.391 0.172 0 0.313 0.125 0.313 0.328v6.531z" fill="rgba(255,255,255,.8)"></path>
          </svg>
        </a>
        <div class="layui-form-select">
          <dl class="layui-nav-child layui-anim layui-anim-upbit" style="position: absolute;top: 0;background-color: rgba(255,255,255,.9);">
            {foreach from="$langs" item="_lang"}
            <dd data-slug="{$_lang.slug}"{if $_lang.slug==$lang} class="layui-this"{/if}>
              <a href="javascript:;" title="{$_lang.name}（{$_lang.title}）" lay-header-event="language">{$_lang.name}（{$_lang.title}）</a>
            </dd>
            {/foreach}
          </dl>
        </div>
      </li>
      {/if}
      <li class="layui-nav-item">
        <a href="{$site_url}/{if $lang!=='zh-CN'}{$lang}/{/if}" target="_blank" title="{$tran.front}"><i class="layui-icon layui-icon-website"></i></a>
      </li>
      <li class="layui-nav-item layui-hide-xs">
        <a href="javascript:;" lay-header-event="refresh" title="{$tran.refresh}"><i class="layui-icon layui-icon-refresh-3"></i></a>
      </li>
    </ul>
    <!-- 头部左侧区域end -->
    <!-- 头部右侧区域 -->
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide-xs" lay-unselect="">
        <a href="javascript:;" lay-header-event="fullscreen">
          <i class="layui-icon layui-icon-screen-full"></i>
        </a>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;"><img src="{$avatar}" class="layui-nav-img" alt="avatar">{$username}</a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;" title="{$tran.modify_profile}" lay-header-event="profile">{$tran.modify_profile}</a>
          </dd>
          <dd><a href="javascript:;" title="{$tran.clear_cache}" lay-header-event="clear">{$tran.clear_cache}</a>
          </dd>
          <dd><a href="javascript:;" title="{$tran.logout}" lay-header-event="logout">{$tran.logout}</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
    <!-- 头部右侧区域end -->
  </div>
  <!-- header end -->

  <!-- aside start -->
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
        <!-- 树型菜单 -->
        {$menus}
        <!-- 树型菜单end -->
      </ul>
      <!-- 左侧导航区end -->
    </div>
  </div>
  <!-- aside end -->

  <!-- main start -->
  <div class="layui-body" id="main-body">
    <!-- 内容主体区域 -->
    <iframe id="main-frame" src="about:blank" scrolling="yes" frameborder="0" style="width: 100%;height:100%;border: 0;"></iframe>
  </div>
  <!-- main end -->

  <!-- footer start -->
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    <div class="layui-word-aux">&copy; Powered by <a href="https://yesu.co/" title="yesu.co" target="_blank" style="color: inherit;">yesu.co</a> {$version}</div>
  </div>
  <!-- footer end -->
</div>

<!-- javascript -->
<script>
  // JS 
  layui.use(['element', 'layer', 'util', 'jquery'], function () {
    var element = layui.element,
      layer = layui.layer,
      util = layui.util,
      $ = layui.jquery;

    // 头部事件
    var full = 1;
    var shrink = true;
    var hash = window.location.hash;
    $('#main-frame').attr('src', '{$site_url}/{if $lang!==\'zh-CN\'}{$lang}/{/if}admin' + (hash.match(/^#\/[^#]+/) ? hash.replace('#', '') : '/index/welcome.html'));
    util.event('lay-header-event', {
      // 后台首页
      backend: function() {
        window.location.hash = '/';
        $('#main-frame').attr('src', '{$site_url}/{if $lang!==\'zh-CN\'}{$lang}/{/if}admin/index/welcome.html');
      },
      // 左侧菜单事件
      menuLeft: function () {
        $('body').addClass('site-mobile');
        $('.layui-logo').removeClass('layui-hide-xs');
      },
      menuLeftShrink: function (obj) {
        if (shrink) {
          shrink = false;
          $('.layui-shrink').removeClass('layui-icon-shrink-right').addClass('layui-icon-spread-left');
          $('.layui-side').addClass('layui-side-shrink');
          $('.layui-logo').addClass('layui-logo-shrink');
          $('.layui-body').addClass('layui-body-shrink');
          $('.layui-layout-left').addClass('layui-layout-left-shrink');
          $('.layui-footer').addClass('layui-footer-shrink');
        } else {
          shrink = true;
          $('.layui-shrink').removeClass('layui-icon-spread-left').addClass('layui-icon-shrink-right');
          $('.layui-side').removeClass('layui-side-shrink');
          $('.layui-logo').removeClass('layui-logo-shrink');
          $('.layui-body').removeClass('layui-body-shrink');
          $('.layui-layout-left').removeClass('layui-layout-left-shrink');
          $('.layui-footer').removeClass('layui-footer-shrink');
        }
      },
      // 遮罩层收缩菜单
      menuShrink: function () {
        $('body').removeClass('site-mobile');
        $('.layui-logo').addClass('layui-hide-xs');
      },
      // 右侧菜单事件
      menuRight: function () {
        layer.open({
          title: '{$tran.info}',
          type: 1,
          content: '<div class="layui-layer-content"><div class="layui-card-header">{$tran.version}</div><div class="layui-card-body layui-text"><blockquote class="layui-elem-quote" style="border: none;">{$tran.current_version}：{$version}</blockquote></div><div class="layui-card-header">{$tran.about}</div><div class="layui-card-body layui-text"><blockquote class="layui-elem-quote" style="border: none;"> {$tran.mvc_info}<br /><br />{$tran.author_info}<br /><br />{$tran.wechat}QQ 869026782 </blockquote></div><div class="layui-card-header">{$tran.reset}</div><div class="layui-card-body layui-text"><blockquote class="layui-elem-quote" style="border: none;">{$tran.reset_system_warning}<br /><br /><button type="button" style="padding: 3px 8px;" lay-header-event="recovery">{$tran.reset_system}</button></blockquote></div></div>',
          area: ['260px', '100%'],
          offset: 'rt', // 右上角
          anim: 5,
          shadeClose: true,
        });
      },
      // 刷新
      refresh: function () {
        window.location.reload();
      },
      // 全屏
      fullscreen: function () {
        if (full == 1) {
          var elem = document.documentElement;
          var reqFullScreen = elem.requestFullScreen || elem.webkitRequestFullScreen || elem.mozRequestFullScreen || elem.msRequestFullscreen;
          if (typeof reqFullScreen !== 'undefined' && reqFullScreen) {
            reqFullScreen.call(elem);
          };
          full = 2;
        } else {
          if (document.exitFullscreen) {
            document.exitFullscreen();
          } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
          } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
          } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
          }
          full = 1;
        }
      },
      // 修改资料
      profile: function (othis) {
        layer.open({
          type: 2,
          maxmin: true,
          title: '{$tran.modify_profile}',
          shadeClose: true,
          shade: 0.3,
          area: ['480px', '470px'],
          content: "{$site_url}/{$lang}/admin/profile.html",
        });
      },
      // 清除缓存
      clear: function (othis) {
        layer.confirm('{$tran.confirm_clear_cache}', {
          title: '{$tran.info}', btn: ['{$tran.ok}', '{$tran.cancel}'], icon: 3
        }, function () {
          $.get("{$site_url}/{$lang}/admin/clear.html", {}, function (res) {
            if (res.code) return layer.alert(res.msg, { title: '{$tran.info}', icon: 0 });
            layer.alert(res.msg, { title: '{$tran.info}', icon: 1 }, function () {
              window.location.reload();
            });
          }, 'json');
        });
      },
      // 登出
      logout: function (othis) {
        layer.confirm('{$tran.confirm_logout}', {
          title: '{$tran.info}', btn: ['{$tran.ok}', '{$tran.cancel}']
        }, function () {
          $.post('{$site_url}/{$lang}/admin/logout.html', {}, function (res) {
            if (res.code) return layer.alert(res.msg, { title: '{$tran.info}', icon: 0 });
            layer.alert(res.msg, { title: '{$tran.info}', icon: 1 });
            setTimeout(function () {
              window.location.href = res.url;
            }, 1000);
          }, 'json');
        });
      },
      // 触发菜单
      fireMenu: function(othis) {
        var lang = othis.data('lang');
        var module = othis.data('module').toLowerCase();
        var controller = othis.data('controller').toLowerCase();
        var action = othis.data('action').toLowerCase();
        window.location.hash = '/' + controller + '/' + action + '.html';
        $('body').removeClass('site-mobile');
        $('.layui-logo').addClass('layui-hide-xs');
        $('#main-frame').attr('src', '{$site_url}/' + (lang === 'zh-CN' ? '' : lang + '/') + module + '/' + controller + '/' + action + '.html');
      },
      // 重置系统
      recovery: function(othis) {
        layer.confirm('{$tran.confirm_recovery}', {
          title: '{$tran.reset_system}',
          btn: ['{$tran.ok}', '{$tran.cancel}'],
          icon: 3
        }, function (index) {
          layer.close(index);
          layer.load(2);
          $.post('{$site_url}/{$lang}/admin/setting/recovery.html', {}, function (res) {
            layer.closeAll('loading');
            if (res.code) return layer.alert(res.msg, { icon: 0 });
            localStorage.removeItem('multiPostViews');
            localStorage.removeItem('multiPostFavorites');
            localStorage.removeItem('multiPostLikes');
            layer.alert(res.msg, { title: '{$tran.info}', icon: 1 });
          }, 'json');
        });
      },
      // 多语切换
      language: function(othis) {
        var slug = othis.parent().data('slug');
        var hash = window.location.hash;
        localStorage.setItem('multiLang', slug);
        window.location.href = '{$site_url}/'+ (slug === 'zh-CN' ? '' : slug + '/') +'admin/'+ (hash.length ? hash : '');
      }
    });

    // Cookie操作
    function setCookie(name, value, options) {
      options = options || {};
      if (value === null) {
          value = '';
          options.expires = -1;
      }
      var expires = '';
      if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
          var date;
          if (typeof options.expires == 'number') {
              date = new Date();
              date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
          } else {
              date = options.expires;
          }
          // use expires attribute, max-age is not supported by IE
          expires = '; expires=' + date.toUTCString();
      }
      var path = options.path ? '; path=' + options.path : '';
      var domain = options.domain ? '; domain=' + options.domain : '';
      var secure = options.secure ? '; secure' : '';
      var c = [name, '=', encodeURIComponent(value)].join('');
      var cookie = [c, expires, path, domain, secure].join('');
      document.cookie = cookie;
    }
    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].trim();
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
  });
</script>

{include file='admin/footer.html'}